<!DOCTYPE html>
<html>
    <head>
        <script src="js/vue.js"></script>
        <script src="js/vuex.js"></script>
    </head>
    <body>
        <div id="app">
            <button @click="calc">计数</button>
            <p>{{this.$store.state.count}}</p>
        </div>
        <script>
            const store = new Vuex.Store({
                state : {
                    count : 0
                },
                mutations : {
                    increment(state) {
                        state.count++
                    }
                },
                actions : {
                    add(context) {
                        context.commit('increment')
                    }
                    // add({commit}){
                    //     commit('increment')
                    // }
                }
            })

            var vm = new Vue({
                el:'#app',
                store,
                methods : {
                    calc() {
                        this.$store.dispatch('add')
                    }
                }
            })
        </script>
    </body>
</html>